Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Fix the deprecation warning of stdext::checked_array_iterator#1769

Open
frederick-vs-ja wants to merge 2 commits into
microsoft:masterfrom
frederick-vs-ja:checked-array-iterator
Open

Fix the deprecation warning of stdext::checked_array_iterator#1769
frederick-vs-ja wants to merge 2 commits into
microsoft:masterfrom
frederick-vs-ja:checked-array-iterator

Conversation

@frederick-vs-ja

@frederick-vs-ja frederick-vs-ja commented Sep 20, 2023

Copy link
Copy Markdown

By adding a non-deprecated copy of checked_array_iterator.

The implementation heavily relies on the implementation details of MSVC STL, but IMO this is OK since we only use it when defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0.

(Attempted to fix) #1768.

@robert-andrzejuk

robert-andrzejuk commented Nov 24, 2023

Copy link
Copy Markdown
Contributor

This should use std::span.

@lederernc

Copy link
Copy Markdown

This should use std::span.

It looks like the rest of the code base is targeting something much older than C++20.

I think this is fine as is.

@kobykahane

Copy link
Copy Markdown

@barcharcraz Can you review this?

@lederernc lederernc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been testing this internally in a conan recipe applying this patch and it works for us.

@pochtmeister

Copy link
Copy Markdown

Is it possible to merge this into main?

@lederernc

lederernc commented Jan 18, 2025

Copy link
Copy Markdown

I recently had to address this when some of our devs upgraded to MSVC 17.12.x and this solution was no longer a workable solution for us.

The solution I ended up deploying with patch files in conan for our team were to modify containerstream.h, producerconsumerstream.h and rawptrstream.h as per this patch file:

diff --git a/Release/include/cpprest/containerstream.h b/Release/include/cpprest/containerstream.h
index 6e949a75..cebd01e6 100644
--- a/Release/include/cpprest/containerstream.h
+++ b/Release/include/cpprest/containerstream.h
@@ -399,7 +399,7 @@ private:
         auto readBegin = std::begin(m_data) + m_current_position;
         auto readEnd = std::begin(m_data) + newPos;
 
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
         // Avoid warning C4996: Use checked iterators under SECURE_SCL
         std::copy(readBegin, readEnd, stdext::checked_array_iterator<_CharType*>(ptr, count));
 #else
diff --git a/Release/include/cpprest/producerconsumerstream.h b/Release/include/cpprest/producerconsumerstream.h
index 3487c460..fc1f2e74 100644
--- a/Release/include/cpprest/producerconsumerstream.h
+++ b/Release/include/cpprest/producerconsumerstream.h
@@ -439,7 +439,7 @@ private:
             _CharType* beg = rbegin();
             _CharType* end = rbegin() + countRead;
 
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
             // Avoid warning C4996: Use checked iterators under SECURE_SCL
             std::copy(beg, end, stdext::checked_array_iterator<_CharType*>(dest, count));
 #else
@@ -462,7 +462,7 @@ private:
 
             const _CharType* srcEnd = src + countWritten;
 
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
             // Avoid warning C4996: Use checked iterators under SECURE_SCL
             std::copy(src, srcEnd, stdext::checked_array_iterator<_CharType*>(wbegin(), static_cast<size_t>(avail)));
 #else
diff --git a/Release/include/cpprest/rawptrstream.h b/Release/include/cpprest/rawptrstream.h
index 1f15ecbe..ed2384d4 100644
--- a/Release/include/cpprest/rawptrstream.h
+++ b/Release/include/cpprest/rawptrstream.h
@@ -439,7 +439,7 @@ private:
         auto readBegin = m_data + m_current_position;
         auto readEnd = m_data + newPos;
 
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
         // Avoid warning C4996: Use checked iterators under SECURE_SCL
         std::copy(readBegin, readEnd, stdext::checked_array_iterator<_CharType*>(ptr, count));
 #else
@@ -466,7 +466,7 @@ private:
         if (newSize > m_size) throw std::runtime_error("Writing past the end of the buffer");
 
             // Copy the data
-#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0
+#if defined(_ITERATOR_DEBUG_LEVEL) && _ITERATOR_DEBUG_LEVEL != 0 && _MSC_VER < 1915
         // Avoid warning C4996: Use checked iterators under SECURE_SCL
         std::copy(ptr, ptr + count, stdext::checked_array_iterator<_CharType*>(m_data, m_size, m_current_position));
 #else

@lederernc

Copy link
Copy Markdown

If it's helpful I can supply an alternate PR with this patch in it. just let me know.

* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*
* This file defines the checked iterator iterator template that originated from MSVC STL's
* stdext::checked_iterator_iterator, which is now deprecated.

@frederick-vs-ja frederick-vs-ja Oct 31, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdext::checked_iterator_iterator is being removed now.

@frederick-vs-ja

Copy link
Copy Markdown
Author

Perhaps the should be abandoned as @StephanTLavavej said the strategy creating a copy was incorrect. Opened #1836 instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants